home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Burning & Media / GB-PVR 1.2.13 / GBPVR10213.msi / Cabs.w1.cab / Photo.aspx.cs398 < prev    next >
Text File  |  2006-11-30  |  7KB  |  169 lines

  1. using System;
  2. using System.Drawing.Imaging;
  3. using System.IO;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Drawing;
  7.  
  8. namespace gbweb
  9. {
  10.     /// <summary>
  11.     /// Summary description for Search.
  12.     /// </summary>
  13.     public partial class Photo : Page
  14.     {
  15.  
  16.         protected void Page_Load(object sender, EventArgs e)
  17.         {
  18.             //Intialize a cookie variable
  19.             HttpCookie cookie;
  20.             
  21.             //If this is the first time coming to the photo page
  22.             if (!IsPostBack)
  23.             {
  24.                 //If the querystring contains a parm of pic convert it to a string and set the url of the image control
  25.                 if (Request.Params["pic"] != null)
  26.                 {
  27.                     picture.ImageUrl = Convert.ToString(Request.Params["pic"]);
  28.                 }
  29.                 else
  30.                 {
  31.                     //Since the querystring did not contain a pic parm we want to hide the image size and rotation
  32.                     //radio buttons
  33.                     photoDiv.Visible = false;
  34.                     return;
  35.                 }
  36.                 //Get the saved coode for the default size of the photo.....this is remembered from session to session
  37.                 cookie = Request.Cookies["photoSize"];
  38.                 photo_Size.SelectedValue = cookie != null ? cookie.Value : "2";
  39.                 
  40.                 //Make the image size and rotation radio buttons visible
  41.                 photoDiv.Visible = true;
  42.             }
  43.  
  44.             //If the image control has its url location set we need to set it to the way the user wants it to display
  45.             if (picture.ImageUrl != null)
  46.             {
  47.                 //To ensure that each display of the picture is accurate we need to reset the url of the image control
  48.                 //to the original value......this is becuase the image url is changed if the user chooses to rotate the image.
  49.                 picture.ImageUrl = Convert.ToString(Request.Params["pic"]);
  50.                 
  51.                 //Split the image url into the page and the actual query string
  52.                 string[] Sfile = picture.ImageUrl.Split('?');
  53.                 
  54.                 //Deserialize the querystring which is the file path and filename
  55.                 string Dfile = (string)PublicDownload.Deseralize(Sfile[1]);
  56.                 
  57.                 //Create an image from the file location
  58.                 Image image = Image.FromFile(Dfile);
  59.                 
  60.                 //Get pull the filename from the picture path to be displayed to the user
  61.                 string photoinfo = Path.GetFileName(Dfile);
  62.                 
  63.                 //Pull the image dimensions from the image to be displayed to the user
  64.                 photoinfo += " - Actual Size: " + image.Width + "x" + image.Height;
  65.                 
  66.                 //Set the info lable to the value of the filename of the image and the image dimensions
  67.                 photoInfo.Text = photoinfo;
  68.  
  69.                 //Set the image display size
  70.                 switch (Convert.ToInt32(photo_Size.SelectedValue))
  71.                 {
  72.                     case 0:
  73.                         {
  74.                             picture.Height = image.Height;
  75.                             picture.Width = image.Width;
  76.                             break;
  77.                         }
  78.                     case 1:
  79.                         {
  80.                             picture.Height = Convert.ToInt32(image.Height * .75);
  81.                             picture.Width = Convert.ToInt32(image.Width * .75);
  82.                             break;
  83.                         }
  84.                     case 2:
  85.                         {
  86.                             picture.Height = Convert.ToInt32(image.Height * .50);
  87.                             picture.Width = Convert.ToInt32(image.Width * .50);
  88.                             break;
  89.                         }
  90.                     case 3:
  91.                         {
  92.                             picture.Height = Convert.ToInt32(image.Height * .25);
  93.                             picture.Width = Convert.ToInt32(image.Width * .25);
  94.                             break;
  95.                         }
  96.                     case 4:
  97.                         {
  98.                             picture.Height = Convert.ToInt32(image.Height * .10);
  99.                             picture.Width = Convert.ToInt32(image.Width * .10);
  100.                             break;
  101.                         }
  102.                     default:
  103.                         {
  104.                             picture.Height = Convert.ToInt32(image.Height * .50);
  105.                             picture.Width = Convert.ToInt32(image.Width * .50);
  106.                             break;
  107.                         }
  108.                 }
  109.  
  110.                 //If the user has choosen to rotate the image then we need to process the image and reset the image sizeing
  111.                 //to work with the rotation option
  112.                 if (photo_Rotation.SelectedValue != "0")
  113.                 {
  114.                     //We must set the url of the rotated image to call download.ashx so that it can be streamed back to the image control
  115.                     picture.ImageUrl = Download.GetDownloadUrl(false, true, Download.InternalFiles.ModifiedPhoto, PublicDownload.Serialize(Dfile + "~" + picture.Height.Value + "~" + picture.Width.Value + "~" + photo_Rotation.SelectedValue));
  116.                     //Depending on the rotation option the height and width of the image control need to be swapped.
  117.                     switch (photo_Rotation.SelectedValue)
  118.                     {
  119.                         case "1":
  120.                             {
  121.                                 double H = picture.Height.Value;
  122.                                 double W = picture.Width.Value;
  123.                                 picture.Height = Convert.ToInt32(W);
  124.                                 picture.Width = Convert.ToInt32(H);
  125.                                 break;
  126.                             }
  127.                         case "3":
  128.                             {
  129.                                 double H = picture.Height.Value;
  130.                                 double W = picture.Width.Value;
  131.                                 picture.Height = Convert.ToInt32(W);
  132.                                 picture.Width = Convert.ToInt32(H);
  133.                                 break;
  134.                             }
  135.                     }
  136.                 }
  137.                //Cleanup
  138.                image.Dispose();
  139.             }
  140.             
  141.             //Store the selected sort order in the cookie for the next image display
  142.             cookie = new HttpCookie("photoSize", photo_Size.SelectedValue);
  143.             cookie.Expires = DateTime.Now.AddYears(1);
  144.             Response.Cookies.Add(cookie);
  145.  
  146.         }
  147.  
  148.         #region Web Form Designer generated code
  149.         override protected void OnInit(EventArgs e)
  150.         {
  151.             //
  152.             // CODEGEN: This call is required by the ASP.NET Web Form Designer.
  153.             //
  154.             InitializeComponent();
  155.             base.OnInit(e);
  156.         }
  157.  
  158.         /// <summary>
  159.         /// Required method for Designer support - do not modify
  160.         /// the contents of this method with the code editor.
  161.         /// </summary>
  162.         private void InitializeComponent()
  163.         {
  164.  
  165.         }
  166.         #endregion
  167.     }
  168. }
  169.